﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Empresa.Sistema.Datos.Entidades;
using Empresa.Sistema.Aplicacion;

namespace Empresa.Sistema.Presentacion
{
    public partial class mntPrestamos : Form
    {
        #region "Instanciar"

        private static mntPrestamos m_FormDefInstance;
        public static mntPrestamos DefInstance
        {
            get
            {
                if (m_FormDefInstance == null || m_FormDefInstance.IsDisposed)
                    m_FormDefInstance = new mntPrestamos();
                return m_FormDefInstance;
            }
            set
            {
                m_FormDefInstance = value;
            }
        }

        #endregion 


        public mntPrestamos()
        {
            InitializeComponent();
        }

        List<Prestamo> lista = new List<Prestamo>();
        public Prestamo pre  = null;
        public string accion;

        private void btnAgregar_Click(object sender, EventArgs e)
        {
            accion = "adicionar";
            var regPrestamo = new regPrestamos();
            regPrestamo.Owner = this;
            regPrestamo.ShowDialog();
        }

        private void btnModificar_Click(object sender, EventArgs e)
        {
            accion = "modificar";
            var regPrestamo = new regPrestamos();
            regPrestamo.Owner = this;
            regPrestamo.ShowDialog();
        }

        private void btnEliminar_Click(object sender, EventArgs e)
        {
            accion = "eliminar";
            var regPrestamo = new regPrestamos();
            regPrestamo.Owner = this;
            regPrestamo.ShowDialog();
        }

        private void mntPrestamos_Load(object sender, EventArgs e)
        {
            lista = new Prestamos().Listar();
            dgvPrestamos.AutoGenerateColumns = false;
            dgvPrestamos.DataSource = lista;  
        }
              
        private void dgvPrestamos_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvPrestamos.CurrentCell.RowIndex >= 0)
            {
                pre = (Prestamo)lista[dgvPrestamos.CurrentCell.RowIndex];
                
            }
        }
    }
}
